using QFramework.Example.Scripts.Event;
using UnityEngine;

namespace QFramework.Example.Scripts.Game
{
    public class Game : MonoBehaviour, IController
    {
        // Start is called before the first frame update
        private void Start()
        {
            this.RegisterEvent<GameStartEvent>(OnGameStart);

            this.RegisterEvent<OnCountDownEndEvent>(e => { transform.Find("Enemies").gameObject.SetActive(false); })
                .UnRegisterWhenGameObjectDestroyed(gameObject);

            this.RegisterEvent<GamePassEvent>(e => { transform.Find("Enemies").gameObject.SetActive(false); })
                .UnRegisterWhenGameObjectDestroyed(gameObject);
        }

        private void OnDestroy()
        {
            this.UnRegisterEvent<GameStartEvent>(OnGameStart);
        }

        IArchitecture IBelongToArchitecture.GetArchitecture()
        {
            return PointGame.Interface;
        }

        private void OnGameStart(GameStartEvent e)
        {
            var enemyRoot = transform.Find("Enemies");
            enemyRoot.gameObject.SetActive(true);

            foreach (Transform childTrans in enemyRoot) childTrans.gameObject.SetActive(true);
        }
    }
}